home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 November / Chip Kasım 2000.iso / prog / share / 41 / data1.cab / Common_E / plugin / slide.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-11-03  |  6.3 KB  |  298 lines

  1. import java.applet.Applet;
  2. import java.awt.Button;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Container;
  6. import java.awt.Event;
  7. import java.awt.Graphics;
  8. import java.awt.Image;
  9. import java.awt.MediaTracker;
  10. import java.awt.Point;
  11. import java.awt.Rectangle;
  12. import java.awt.image.ImageObserver;
  13.  
  14. public class slide extends Applet implements Runnable {
  15.    private Thread m_slide;
  16.    private Button m_PrevButton;
  17.    private Button m_NextButton;
  18.    private Button m_FirstButton;
  19.    private Button m_LastButton;
  20.    private Button m_ForwardButton;
  21.    private Button m_BackwardButton;
  22.    private Button m_StopButton;
  23.    private Button m_PauseButton;
  24.    private boolean m_fInit;
  25.    private Graphics m_Graphics;
  26.    private Image m_Image;
  27.    private int m_nCurrImage;
  28.    private int m_nImgWidth;
  29.    private int m_nImgHeight;
  30.    private boolean m_fLoaded;
  31.    private boolean m_pause;
  32.    private Color m_backColor;
  33.    private Point m_ptName;
  34.    private Rectangle m_rcImage;
  35.    private int m_imgnum = 3;
  36.    private int m_sleep = 1000;
  37.    private boolean m_zoom = true;
  38.    private int m_maxwidth;
  39.    private int m_maxheight;
  40.    private boolean m_srcname;
  41.    private int m_redback;
  42.    private int m_greenback;
  43.    private int m_blueback;
  44.    private boolean m_haspanel;
  45.    private String m_imgname;
  46.    private final String PARAM_imgnum = "imgnum";
  47.    private final String PARAM_sleep = "sleep";
  48.    private final String PARAM_zoom = "zoom";
  49.    private final String PARAM_maxwidth = "maxwidth";
  50.    private final String PARAM_maxheight = "maxheight";
  51.    private final String PARAM_srcname = "srcname";
  52.    private final String PARAM_redback = "redback";
  53.    private final String PARAM_greenback = "greenback";
  54.    private final String PARAM_blueback = "blueback";
  55.    private final String PARAM_haspanel = "haspanel";
  56.    private final String PARAM_imgname = "img";
  57.  
  58.    public void stop() {
  59.       if (this.m_slide != null) {
  60.          this.m_slide.stop();
  61.          this.m_slide = null;
  62.       }
  63.  
  64.       this.m_pause = true;
  65.    }
  66.  
  67.    public void paint(Graphics var1) {
  68.       if (this.m_fLoaded) {
  69.          this.displayImage(var1);
  70.       }
  71.  
  72.    }
  73.  
  74.    public String[][] getParameterInfo() {
  75.       String[][] var1 = new String[][]{{"imgnum", "int", "Number of images"}, {"sleep", "int", "Sleep time (ms)"}, {"zoom", "int", "Zoom or not"}, {"maxwidth", "int", "Max image width"}, {"maxheight", "int", "Max image height"}, {"srcname", "int", "Show source name or not"}, {"redback", "int", "Back color of red"}, {"greenback", "int", "Back color of green"}, {"blueback", "int", "Back color of blue"}, {"haspanel", "int", "Show control panel or not"}};
  76.       return var1;
  77.    }
  78.  
  79.    private String parseFilename(String var1) {
  80.       String var2 = var1.trim();
  81.       int var3 = var2.length();
  82.       if (var3 == 0) {
  83.          return var1;
  84.       } else {
  85.          do {
  86.             --var3;
  87.          } while(var3 >= 0 && var2.charAt(var3) != '\\' && var2.charAt(var3) != '/');
  88.  
  89.          ++var3;
  90.          return var2.substring(var3);
  91.       }
  92.    }
  93.  
  94.    public void destroy() {
  95.    }
  96.  
  97.    private void displayImage(Graphics var1) {
  98.       if (this.m_fLoaded) {
  99.          this.m_fLoaded = false;
  100.          var1.setColor(this.m_backColor);
  101.          var1.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
  102.          if (this.m_srcname) {
  103.             var1.setColor(new Color(255, 255, 255));
  104.             var1.drawString(this.parseFilename(this.m_imgname), this.m_ptName.x, this.m_ptName.y);
  105.          }
  106.  
  107.          if (this.m_zoom) {
  108.             float var2 = (float)this.m_nImgWidth / (float)this.m_nImgHeight;
  109.             float var3 = (float)this.m_rcImage.width / (float)this.m_rcImage.height;
  110.             if (this.m_nImgWidth > this.m_rcImage.width || this.m_nImgHeight > this.m_rcImage.height) {
  111.                if (var2 > var3) {
  112.                   this.m_nImgWidth = this.m_rcImage.width;
  113.                   this.m_nImgHeight = (int)((float)this.m_nImgWidth / var2);
  114.                } else {
  115.                   this.m_nImgHeight = this.m_rcImage.height;
  116.                   this.m_nImgWidth = (int)((float)this.m_nImgHeight * var2);
  117.                }
  118.             }
  119.          }
  120.  
  121.          int var4 = this.m_rcImage.x;
  122.          int var5 = this.m_rcImage.y;
  123.          if (this.m_nImgWidth < this.m_rcImage.width) {
  124.             var4 += (this.m_rcImage.width - this.m_nImgWidth) / 2;
  125.          }
  126.  
  127.          if (this.m_nImgHeight < this.m_rcImage.height) {
  128.             var5 += (this.m_rcImage.height - this.m_nImgHeight) / 2;
  129.          }
  130.  
  131.          if (this.m_zoom) {
  132.             var1.drawImage(this.m_Image, var4, var5, this.m_nImgWidth, this.m_nImgHeight, (ImageObserver)null);
  133.          } else {
  134.             var1.drawImage(this.m_Image, var4, var5, (ImageObserver)null);
  135.          }
  136.       }
  137.    }
  138.  
  139.    public void start() {
  140.       if (this.m_slide == null) {
  141.          this.m_slide = new Thread(this);
  142.          this.m_slide.start();
  143.       }
  144.  
  145.       this.m_pause = false;
  146.       if (!this.m_fInit && this.m_haspanel) {
  147.          this.m_fInit = true;
  148.          Rectangle var1 = this.m_LastButton.bounds();
  149.          Rectangle var10000 = this.m_rcImage;
  150.          var10000.y += var1.height + var1.y;
  151.          this.m_rcImage.height = ((Component)this).size().height - this.m_rcImage.y;
  152.          Point var2 = this.m_ptName;
  153.          var2.y += var1.height + var1.y;
  154.       }
  155.  
  156.    }
  157.  
  158.    public String getAppletInfo() {
  159.       return "Name: slide\r\n" + "Author: Roger Zhang\r\n" + "Created with Microsoft Visual J++ Version 1.1";
  160.    }
  161.  
  162.    public boolean mouseDown(Event var1, int var2, int var3) {
  163.       if (this.m_haspanel) {
  164.          return super.mouseDown(var1, var2, var3);
  165.       } else {
  166.          if (this.m_slide != null) {
  167.             if (this.m_pause) {
  168.                this.m_slide.resume();
  169.             } else {
  170.                this.m_slide.suspend();
  171.             }
  172.  
  173.             this.m_pause = !this.m_pause;
  174.          } else {
  175.             this.start();
  176.          }
  177.  
  178.          return true;
  179.       }
  180.    }
  181.  
  182.    public void run() {
  183.       this.m_nCurrImage = 0;
  184.       this.m_Graphics = ((Component)this).getGraphics();
  185.       MediaTracker var1 = new MediaTracker(this);
  186.  
  187.       while(true) {
  188.          this.m_imgname = ((Applet)this).getParameter("img" + (this.m_nCurrImage + 1));
  189.          this.m_Image = ((Applet)this).getImage(((Applet)this).getDocumentBase(), this.m_imgname);
  190.          var1.addImage(this.m_Image, 0);
  191.          ((Applet)this).showStatus("Loading " + this.m_imgname);
  192.  
  193.          try {
  194.             var1.waitForAll();
  195.             this.m_fLoaded = !var1.isErrorAny();
  196.          } catch (InterruptedException var2) {
  197.          }
  198.  
  199.          if (!this.m_fLoaded) {
  200.             this.stop();
  201.             this.m_Graphics.drawString("Error loading images!", 10, 40);
  202.             return;
  203.          }
  204.  
  205.          this.m_nImgWidth = this.m_Image.getWidth(this);
  206.          this.m_nImgHeight = this.m_Image.getHeight(this);
  207.  
  208.          try {
  209.             this.displayImage(this.m_Graphics);
  210.             ++this.m_nCurrImage;
  211.             if (this.m_nCurrImage == this.m_imgnum) {
  212.                this.m_nCurrImage = 0;
  213.             }
  214.  
  215.             Thread.sleep((long)this.m_sleep);
  216.          } catch (InterruptedException var3) {
  217.             this.stop();
  218.          }
  219.       }
  220.    }
  221.  
  222.    public void init() {
  223.       String var1 = ((Applet)this).getParameter("imgnum");
  224.       if (var1 != null) {
  225.          this.m_imgnum = Integer.parseInt(var1);
  226.       }
  227.  
  228.       var1 = ((Applet)this).getParameter("sleep");
  229.       if (var1 != null) {
  230.          this.m_sleep = Integer.parseInt(var1);
  231.       }
  232.  
  233.       var1 = ((Applet)this).getParameter("zoom");
  234.       if (var1 != null) {
  235.          this.m_zoom = Integer.parseInt(var1) != 0;
  236.       }
  237.  
  238.       var1 = ((Applet)this).getParameter("maxwidth");
  239.       if (var1 != null) {
  240.          this.m_maxwidth = Integer.parseInt(var1);
  241.       }
  242.  
  243.       var1 = ((Applet)this).getParameter("maxheight");
  244.       if (var1 != null) {
  245.          this.m_maxheight = Integer.parseInt(var1);
  246.       }
  247.  
  248.       var1 = ((Applet)this).getParameter("srcname");
  249.       if (var1 != null) {
  250.          this.m_srcname = Integer.parseInt(var1) != 0;
  251.       }
  252.  
  253.       var1 = ((Applet)this).getParameter("redback");
  254.       if (var1 != null) {
  255.          this.m_redback = Integer.parseInt(var1);
  256.       }
  257.  
  258.       var1 = ((Applet)this).getParameter("greenback");
  259.       if (var1 != null) {
  260.          this.m_greenback = Integer.parseInt(var1);
  261.       }
  262.  
  263.       var1 = ((Applet)this).getParameter("blueback");
  264.       if (var1 != null) {
  265.          this.m_blueback = Integer.parseInt(var1);
  266.       }
  267.  
  268.       var1 = ((Applet)this).getParameter("haspanel");
  269.       if (var1 != null) {
  270.          this.m_haspanel = Integer.parseInt(var1) != 0;
  271.       }
  272.  
  273.       this.m_backColor = new Color(this.m_redback, this.m_greenback, this.m_blueback);
  274.       this.m_ptName = new Point(20, 20);
  275.       int var2 = this.m_srcname ? 40 : 0;
  276.       this.m_rcImage = new Rectangle(0, var2, ((Component)this).size().width, ((Component)this).size().height - var2);
  277.       if (this.m_haspanel) {
  278.          this.m_StopButton = new Button("Stop");
  279.          this.m_PauseButton = new Button("Pause");
  280.          this.m_BackwardButton = new Button("<<");
  281.          this.m_ForwardButton = new Button(">>");
  282.          this.m_FirstButton = new Button("|<");
  283.          this.m_PrevButton = new Button("<");
  284.          this.m_NextButton = new Button(">");
  285.          this.m_LastButton = new Button(">|");
  286.          ((Container)this).add(this.m_StopButton);
  287.          ((Container)this).add(this.m_PauseButton);
  288.          ((Container)this).add(this.m_BackwardButton);
  289.          ((Container)this).add(this.m_ForwardButton);
  290.          ((Container)this).add(this.m_FirstButton);
  291.          ((Container)this).add(this.m_PrevButton);
  292.          ((Container)this).add(this.m_NextButton);
  293.          ((Container)this).add(this.m_LastButton);
  294.       }
  295.  
  296.    }
  297. }
  298.